<?php

/* 
 * Classe Module
 */

namespace Ticket;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module{
    /**
     * Démarrage du Module
     * Chargement du Nom du Controller
     * Chargement du Nom de l'Action
     * Chargement du Nom du Module
     *
     * @param \Zend\Mvc\MvcEvent $e
     */
    public function onBootstrap(MvcEvent $e) {
	$eventManager		 = $e->getApplication()->getEventManager();
	$moduleRouteListener	 = new ModuleRouteListener();
	$moduleRouteListener->attach($eventManager);

	$sharedEvents = $eventManager->getSharedManager();
	$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
		    $controller	 = $e->getTarget();
		    $route		 = $controller->getEvent()->getRouteMatch();
                    //$controller->layout('');
		    $e->getViewModel()->setVariables(
			    array('controllerName' => $route->getParam('__CONTROLLER__', 'index'),
				'actionName'	 => $route->getParam('action', 'index'),
				'moduleName'	 => strtolower(__NAMESPACE__),
                                )
		    );
		}, 100);
    }
    
    /**
     * Configuration de l'AutoLoader de Zend
     *
     * @return array
     */
    public function getAutoloaderConfig() {
	return array(
	    'Zend\Loader\ClassMapAutoloader' => array(
		__DIR__ . '/autoload_classmap.php',
	    ),
	    'Zend\Loader\StandardAutoloader' => array(
		'namespaces' => array(
		    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
		),
	    ),
	);
    }

    /**
     * Fichier de Configuration du Module
     *
     * @return File
     */
    public function getConfig() {
	return include __DIR__ . '/config/module.config.php';
    }
    
    /**
     * Services
     * 
     * @return type
     */
    public function getServiceConfig(){
        return array(
            'factories' => array(
                //
            ),
        );
    }
}

